using System;
using UnityEditor;
using UnityEngine;

namespace Game.Editor
{
    public static class EditorUtil
    {
        public static float GetLinesHeightWithNarrowModeSupport(int count) {
            if (!EditorGUIUtility.wideMode) {
                count++;
            }
            return count * (EditorGUIUtility.singleLineHeight) + (count - 1) * EditorGUIUtility.standardVerticalSpacing;
        }
        
        public sealed class PropertyScope : IDisposable {

            public PropertyScope(Rect position, GUIContent label, SerializedProperty property) {
                EditorGUI.BeginProperty(position, label, property);
            }

            public void Dispose() {
                EditorGUI.EndProperty();
            }
        }
        
        public sealed class LabelWidthScope : IDisposable {
            private readonly float _currentLabelWidth;

            public LabelWidthScope(float labelWidth) {
                _currentLabelWidth          = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = labelWidth;
            }

            public void Dispose() {
                EditorGUIUtility.labelWidth = _currentLabelWidth;
            }
        }
        
    }
}